function onPickerNum(num,unitprice){
	return unitprice * 10000 * num / 10000;
}


function doPay(buyid,goods,money){
	$.confirm('现在付款?',function () {
		var ajaxurl="<%=rootPath%>/weixin/pay/weixinpay";
		var spbill_create_ip = "<%=remoteip%>";
		$.ajax({
             type: "POST",
             url: ajaxurl,//点击登录按钮走的action
             async: false,
             data:{buyId:buyid,money:money,categoryname:goods,spbill_create_ip:spbill_create_ip},
             dataType: "json",
             success: function(data){
            	 callpay(data.weixinpay.appId,
            			 data.weixinpay.timeStamp,
            			 data.weixinpay.nonceStr,
            			 data.weixinpay.paypackage,
            			 data.weixinpay.paySign,buyid)
             },
             error: function(data){
		alert("weixin json fail");
            	 $.alert(data.msg);
             }
         });
	},function () {$.alert('您取消了订单');}
	);
}


function callpay(appId,timeStamp,nonceStr,paypackage,paySign,buyid){   
	WeixinJSBridge.invoke('getBrandWCPayRequest',
			{"appId" :appId,"timeStamp" : timeStamp,"nonceStr" : nonceStr,"package" :paypackage,"signType" : "MD5", "paySign" :paySign},
    function(res){
				WeixinJSBridge.log(res.err_msg);
//	     alert(res.err_code + res.err_desc + res.err_msg);
			if(res.err_msg == "get_brand_wcpay_request:ok"){  
				$.alert("微信支付成功!");  
				//跳转待发货页面
				doUpdateOrderPayState(buyid,'1');
			    window.location.href='orderList.html';
			}else if(res.err_msg == "get_brand_wcpay_request:cancel"){  
				$.alert("用户取消支付!");
				doUpdateOrderPayState(buyid,'-2');
				//跳转待支付页面
			}else{  
				$.alert("支付失败!"); 
				doUpdateOrderPayState(buyid,'-1');
				//跳转到首页；
				window.location.href="<%=rootPath%>/weixin/weixinindex";
			}  
 		})
}

function doUpdateOrderPayState(buyid,opeartor){
	var ajaxurl="<%=rootPath%>/json/updatePayState";
	$.ajax({
            type: "POST",
            url: ajaxurl,//点击登录按钮走的action
            data:{paystate:opeartor,buyid:buyid},
            async: false,
            dataType: "json",
            success: function(data){},
            error: function(data){}
        });
}
